﻿using System;
using System.Collections.Generic;
using System.Text;
using Kiiro.Common.Entities;
using Kiiro.Common.Utility;
using Kiiro.Validation.Interfaces;

namespace Kiiro.Validation.Validators.Entities
{
    public class CommentValidator : BaseEntityValidator, IValidator<Comment>
    {
        private readonly List<ValidationMessage> validationErrors = new List<ValidationMessage> ( );

        #region  IValidator<Comment> Members
        public List<ValidationMessage> Validate ( Comment entityToValidate )
        {
            // If the entity is marked as deleted, don't do any validation, just return.
            if ( entityToValidate.EditType != EditType.Deleted )
            {
                ValidationMessage message = null;

                #region Required Fields Checks

                message = IsRequired ( entityToValidate.Text, "Text" );

                if ( message != null )
                {
                    entityToValidate.TextMessage.Add ( message );
                    validationErrors.Add ( message );
                }

                message = IsRequired(entityToValidate.DiscussionId, "Discussion Id");

                if (message != null)
                {
                    entityToValidate.DiscussionIdMessage.Add(message);
                    validationErrors.Add(message);
                }

                #endregion

                #region Comparison Checks

                if ( !string.IsNullOrEmpty ( entityToValidate.Text ) )
                {
                    message = CheckMaximumLength ( 2000, entityToValidate.Text, "Comment Text" );

                    if ( message != null )
                    {
                        entityToValidate.TextMessage.Add ( message );
                        validationErrors.Add ( message );
                    }

                    //message = HasScriptingTagsInText ( entityToValidate.Text, "Comment Text" );

                    //if ( message != null )
                    //{
                    //    entityToValidate.TextMessage.Add ( message );
                    //    validationErrors.Add ( message );
                    //}
                }
                #endregion
            }

            return validationErrors;
        }
        #endregion
    }
}

/*************************************************************************
 * 
 * $Log: /Internal Projects/Kiiro/Kiiro.Validation/Validators/Entities/CommentValidator.cs $
 * 
 * 6     1/15/10 9:14a Camerons
 * 
 * 5     10/26/09 10:42a Adamw
 * 
 * 4     10/23/09 1:41p Adamw
 * Case 332, script tag check
 * 
 * 3     17/08/09 10:45a Camerons
 * Added check-in comments section
 * 
 ************************************************************************/